#include "DeviceZigbeeManager.h"
#include "tool.h"

Device_zigbee_control DeviceZigbeeManager::getCommandSocketCtrl(long address,long socket,long msgId){
    
    Device_zigbee_control  deviceZigbeeControl;

    if(address<0||address>65535){
        deviceZigbeeControl.result_err = ERR_DATA_RANGE;
        return deviceZigbeeControl;
    }

    if(socket<0 || socket>2){
        deviceZigbeeControl.result_err = ERR_DATA_RANGE;
        return deviceZigbeeControl;
    }

    deviceZigbeeControl.result_err = ERR_OK;


    char *address_str = (char *)malloc(sizeof(char)*5);
    longToStr(address,address_str);
    *(address_str+4) = '\0';

    deviceZigbeeControl.data1 = (string)address_str + "000603";
    

    char *msgId_str = (char *)malloc(sizeof(char)*3);
    longToStr(msgId,msgId_str);
    *(msgId_str+2) = '\0';
    char *socket_str = (char *)malloc(sizeof(char)*3);
    longToStr(socket,socket_str);
    *(socket_str+2) = '\0';
     deviceZigbeeControl.data2 = "01" + (string)msgId_str + (string)socket_str;
 
   free(msgId_str);
    free(socket_str);

  return deviceZigbeeControl;
}


Device_zigbee_control DeviceZigbeeManager::getCommandRemoteTestCtrl(long address ,long msgId){
    Device_zigbee_control deviceZigbeeControl;




    if(address<0||address>65535){
        deviceZigbeeControl.result_err = ERR_DATA_RANGE;
        return deviceZigbeeControl;
    }

    deviceZigbeeControl.result_err = ERR_OK;

    char *address_str = (char *)malloc(sizeof(char)*5);
    longToStr(address,address_str);
    *(address_str+4) = '\0';


    deviceZigbeeControl.data1 = (string)address_str + "050007";

    char *msgId_str = (char *)malloc(sizeof(char)*3);
    longToStr(msgId,msgId_str);
    *(msgId_str+2) = '\0';


    deviceZigbeeControl.data2 = "050912" + (string)msgId_str + "800010";
   
    free(msgId_str);

    return deviceZigbeeControl;
}